/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package org.tnmk.worktime.utils;

import java.text.DecimalFormat;
import java.text.NumberFormat;

/**
 *
 * @author tnmkhoi
 */
public class NumUtils {
  public static String toString(Number num){
    NumberFormat fm = DecimalFormat.getInstance();
    fm.setMaximumFractionDigits(3);
    String s = fm.format(num);
    return s;
  }
  public static String toString(Number num, int numChar){
    String rs = String.format("%0"+numChar+"d", num);
    return rs;
  }
  public static Long toLong(Object val){
    if (val == null) return null;
    if (val instanceof Long){
      return (Long)val;
    }else{
      return Long.valueOf(val.toString());
    }
  }
  public static Float toFloat(Object val){
    if (val == null) return null;
    if (val instanceof Float){
      return (Float)val;
    }else{
      return Float.valueOf(val.toString());
    }
  }
}
